package com.rory.gooday.common;

import java.util.Objects;

public class R {

    private int code;

    private String msg;

    private Object data;

    public static R ok() {
        R r = new R();
        r.setCode(200);
        return r;
    }
    public static R ok(Object data) {
    	R r = new R();
    	r.setCode(200);
    	r.setData(data);
    	return r;
    }

    public static R error() {
        R r = new R();
        r.setCode(500);
        r.setData(null);
        return r;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;

        R r = (R) o;
        return code == r.code && Objects.equals(msg, r.msg) && Objects.equals(data, r.data);
    }

    @Override
    public int hashCode() {
        int result = code;
        result = 31 * result + Objects.hashCode(msg);
        result = 31 * result + Objects.hashCode(data);
        return result;
    }
}
